import { useState, useEffect } from 'react';

// 自定义 Hook 用于监测屏幕宽度
export default function useScreenSize() {
  const [screenWidth, setScreenWidth] = useState(window.innerWidth);

  const handleResize = () => {
    setScreenWidth(window.innerWidth);
  };

  useEffect(() => {
    window.addEventListener('resize', handleResize);

    return () => {
      window.removeEventListener('resize', handleResize);
    };
  }, []);

  return { width: screenWidth };
}
